#!/bin/bash

processId=$(netstat -anp | grep 9096 | grep LISTEN | awk '{print $7}' | awk -F "/" '{print $1}')

echo "Process Id is $processId"

# stop process by pid
if [ ! $processId ]; then
  echo "Process not running"
else
  kill -9 $processId
  echo "WebSite kill success (PId: $processId)"
fi

# pull source from gitee
echo "wait pull source from gitee ..."
cd ak-soft-page
git pull

# build source
echo "build source"
npm install
npm run build

# run web site
cd ..
nohup npx http-server -p 9096 ./ak-soft-page/build > running.log 2>&1 &
echo "Process start success, wait for tail loging :"

